use std::{
    clone,
    fmt::{Debug, Display},
};
pub trait Summary {
    fn summarize_author(&self) -> String;

    fn summarize(&self) -> String {
        format!("(Read more from {}...)", self.summarize_author())
    }
}
#[derive(Debug, Clone)]
pub struct NewsArticle {
    pub headline: String,
    pub location: String,
    pub author: String,
    pub content: String,
}

impl Summary for NewsArticle {
    fn summarize_author(&self) -> String {
        format!("{}, by {} ({})", self.headline, self.author, self.location)
    }
}

pub fn notify(item: &impl Summary, item2: &impl Summary) {
    // println!("{:?}", item)
}
pub fn notify2<T: Summary + Clone + Debug>(item: &T, item2: &T) {
    let res = format!("{}", item.clone().summarize());
    let res2 = item2.clone();
    println!("{},{:#?}", res, res2)
}
pub fn notify3<T, U>(item: &T, item2: &U)
where
    T: Summary,
    U: Summary + Debug + Clone,
{
    let res = format!("{}", item.summarize());
    let res2 = item2.clone();
    println!("{},{:#?}", res, res2)
}
#[derive(Debug)]
struct Pair<T> {
    x: T,
    y: T,
}

impl<T> Pair<T> {
    fn new(x: T, y: T) -> Self {
        Self { x, y }
    }
}

impl<T: Display + PartialOrd> Pair<T> {
    fn cmp_display(&self) {
        if self.x >= self.y {
            println!("The largest member is x = {}", self.x);
        } else {
            println!("The largest member is y = {}", self.y);
        }
    }
}
fn main() {
    let mut article = NewsArticle {
        headline: String::from("Penguins win the Stanley Cup Championship!"),
        location: String::from("Pittsburgh, PA, USA"),
        author: String::from("Iceburgh"),
        content: String::from(
            "The Pittsburgh Penguins once again are the best
    hockey team in the NHL.",
        ),
    };
    notify(&article, &article);

    notify2(&article, &article);
    notify3(&article, &article);
    returns_summarizable(&mut article);
    // returns_summarizable(&article);
    // notify();
    // println!("Hello, world!,{}", article.summarize());
    let res = Pair::new(1, 2);
    res.cmp_display();
    println!("{:?}", &res)
}
fn returns_summarizable(_item: &mut NewsArticle) -> &dyn Summary {
    _item
}
